package com.wzy.springstrage;

import lombok.Data;

/**
 * @Auther: wzy
 * @Date: 2021/12/11/10:15
 * @Description:
 */
@Data
public class CommonPairResponse<T, R> {
    private R code;
    private String message;
    private T data;

    /**
     * 成功，无返回
     *
     * @return Result
     **/
    public static CommonPairResponse success() {
        return success(null, null);
    }

    /**
     * 成功，返回结果
     *
     * @param data 泛型结果
     * @return Result
     **/
    public static <T, R> CommonPairResponse success(T data, R code) {
        CommonPairResponse<T, R> result = new CommonPairResponse<>();
        result.setCode(code);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    /**
     * 成功，返回结果
     *
     * @param message 正确信息
     * @return Result
     **/
    public static CommonPairResponse success(String message) {
        CommonPairResponse result = new CommonPairResponse<>();
        result.setCode("200");
        result.setMessage(message);
        return result;
    }

    public static CommonPairResponse failure(String s) {
        CommonPairResponse result = new CommonPairResponse<>();
        result.setCode("404");
        result.setMessage(s);
        return result;
    }
}
